/**
 * 读取hdfs中的文件
 */
package net.zwj.hadoop.dfs;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

/**
 * @author zhouwj
 * 
 */
public class FileSystemCat {

	public static void main(String[] args) throws IOException {
		String uri = args[0];
//		String uri = "hdfs://192.168.100.45:9000/1.txt";
		Configuration conf = new Configuration();
		
		System.out.println("location: "+conf.get("fs.default.name"));
		FileSystem fs = FileSystem.get(URI.create(uri), conf);
		InputStream in = null;
		try{
			in = fs.open(new Path(uri));
			IOUtils.copyBytes(in, System.out, 4096,false);
		}finally{
			IOUtils.closeStream(in);
		}
		
	}

}
